package tongcheng.com.tongcheng.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import tongcheng.com.tongcheng.R;
import tongcheng.com.tongcheng.base.BaseViewHolder;
import tongcheng.com.tongcheng.bean.QiangDanPeopleBean;

/**
 * Created by P on 2017/8/2.
 */

public class QiangDanPeopleDetialAdapter extends RecyclerView.Adapter<QiangDanPeopleDetialAdapter.QiangdanViewHolder> {

    public Context mContext;
    public List<QiangDanPeopleBean.DataBean> datas;

    public QiangDanPeopleDetialAdapter(Context context, List<QiangDanPeopleBean.DataBean> datas) {
        this.mContext = context;
        this.datas = datas;
    }

    @Override
    public QiangdanViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = View.inflate(mContext, R.layout.item_orderpeoplelist, null);
        QiangdanViewHolder qiangdanViewHolder = new QiangdanViewHolder(view);

        return qiangdanViewHolder;
    }

    @Override
    public void onBindViewHolder(final QiangdanViewHolder holder, final int position) {
        final QiangDanPeopleBean.DataBean dataBean = datas.get(position);
        holder.right.setText(dataBean.user_name + "");
        holder.right1.setText(dataBean.record+"");
        if (!TextUtils.isEmpty(dataBean.documents_features)) {
            String[] split = dataBean.documents_features.split(",");
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
            linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
            holder.people_rc.setLayoutManager(linearLayoutManager);
            ThreeImageAdapter threeImageAdapter = new ThreeImageAdapter(mContext,split);
            holder.people_rc.setAdapter(threeImageAdapter);
        }


        holder.right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {




                if (dataBean.isCheck==true) {
                    holder.topImage.setImageResource(R.mipmap.weixuanze);
                    for (int i = 0; i < datas.size(); i++) {
                        QiangDanPeopleBean.DataBean dataBean1 = datas.get(i);
                        dataBean1.isCheck = false;
                    }

                } else if (dataBean.isCheck==false) {

                    holder.topImage.setImageResource(R.mipmap.queding);

                    for (int i = 0; i < datas.size(); i++) {
                        QiangDanPeopleBean.DataBean dataBean1 = datas.get(i);
                        dataBean1.isCheck = i == position;

                    }

                }
            }
        });
        holder.topImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (dataBean.isCheck==true) {
                    holder.topImage.setImageResource(R.mipmap.weixuanze);
                    dataBean.isCheck = false;
                } else if (dataBean.isCheck==false) {
                    dataBean.isCheck = true;
                    holder.topImage.setImageResource(R.mipmap.queding);
                }

            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class QiangdanViewHolder extends BaseViewHolder{


        public TextView right,right1, right2;

        public RecyclerView people_rc;

        public ImageView topImage;

        public QiangdanViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void init(View itemview) {
            right=    itemview.findViewById(R.id.item_qiangdan_people_top_right);
            right1=  itemview.findViewById(R.id.item_qiangdan_people_all_right1);
            right2=  itemview.findViewById(R.id.item_qiangdan_people_all_right2);
            people_rc= itemview.findViewById(R.id.item_qiangdan_people_rc);

            topImage=itemview.findViewById(R.id.item_qiangdan_people_top_image);
        }
    }


}
